/*
 * @Author: xiaosihan
 * @Date: 2021-04-10 18:25:35
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2021-05-04 21:20:39
 */

import { Vector3 } from "three";
import Transition from "./Transition";

// 待缓动效果的3d顶点
export default class TransitionVector3 extends Vector3 {

    constructor(x = 0, y = 0, z = 0) {
        super(x, y, z);

        this._transition = new Transition({ x, y, z, });

        Object.defineProperties(this, {
            x: {
                set(v) {
                    this._transition.x = v;
                },
                get() {
                    return this._transition.x;
                }
            },
            y: {
                set(v) {
                    this._transition.y = v;
                },
                get() {
                    return this._transition.y;
                }
            },
            z: {
                set(v) {
                    this._transition.z = v;
                },
                get() {
                    return this._transition.z;
                }
            },
        });

    }

    _transition!: Transition;

    setDuration(duration: number = 500) {
        this._transition.setDuration(duration);
        return this;
    }

    setBezier(bezier: [number, number, number, number] = [0.8, 0, 0.2, 1]) {
        this._transition.setBezier(bezier);
        return this;
    }

    // 设置起始位置
    setStart({ x, y, z }: { [key: string]: number } | Vector3 = {}) {
        this._transition.setStart({ x, y, z });
        return this;
    }

    // 设置起始位置
    setEnd({ x, y, z }: { [key: string]: number } | Vector3 = {}) {
        this._transition.setEnd({ x, y, z });
        return this;
    }

    // 设置起始位置
    reset({ x, y, z }: { [key: string]: number } | Vector3 = {}) {
        this._transition.reset({ x, y, z });
        return this;
    }

    isDone() {
        return this._transition.isDone();
    }

}